home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cpptut22.zip / POINTERS.CPP < prev    next >
C/C++ Source or Header  |  1992-01-20  |  688b  |  34 lines

  1.                                       // Chapter 3 - Program 1
  2. #include <iostream.h>
  3.  
  4. main()
  5. {
  6. int   *pt_int;
  7. float *pt_float;
  8. int   pig = 7, dog = 27;
  9. float x = 1.2345, y = 32.14;
  10. void *general;
  11.  
  12.    pt_int = &pig;
  13.    *pt_int += dog;
  14.    cout << "Pig now has the value of " << *pt_int << "\n";
  15.    general = pt_int;
  16.  
  17.    pt_float = &x;
  18.    y += 5 * (*pt_float);
  19.    cout << "y now has the value of " << y << "\n";
  20.    general = pt_float;
  21.  
  22.    const char *name1 = "John";    // Value cannot be changed
  23.    char *const name2 = "John";    // Pointer cannot be changed
  24. }
  25.  
  26.  
  27.  
  28.  
  29. // Result of execution
  30. //
  31. // Pig now has the value of 34
  32. // y now has the value of 38.3125
  33.  
  34.